package org.or5e.service.core.ds;

import org.hibernate.SessionFactory;
import org.or5e.core.BaseObject;
import org.or5e.service.core.sm.SessionManager;

public abstract class BasicDataSource extends BaseObject implements LifeCycle{
	protected SessionFactory sessionFactory = null;
	protected SessionManager sessionManager = null;
	
	public BasicDataSource(SessionFactory sessionFactory, SessionManager sessionManager) {
		this.sessionManager = sessionManager;
		this.sessionFactory = sessionFactory;
	}
	@Override public void initilizeDataSource() {
		this.sessionManager.init();
		debug("Initilized Data Source is called from :"+this.getName());
	}
	@Override public void closeDataSource() {
		debug("Close Data Source is called from :"+this.getName());
		this.sessionManager.destroy();
		if(this.sessionFactory.isClosed()) {
			debug("Session Factory is not Closed.");
			this.sessionFactory.close();
		}
	}
}
